Re: [GENERAL] DISPLAYING BLOBS/images/text - Mailing list pgsql-general

From Herouth Maoz
Subject Re: [GENERAL] DISPLAYING BLOBS/images/text
Date
Msg-id l03110704b2d0a5128a9b@[147.233.159.109]
Whole thread Raw
In response to DISPLAYING BLOBS/images/text  ("Martin Wong" <martin@minook.com.sg>)
Responses Re: [GENERAL] DISPLAYING BLOBS/images/text
List pgsql-general
At 14:02 +0200 on 22/1/99, Martin Wong wrote:


> I have a pgsql database table packed with images and another one packed with
> text files, all blobs. I have a script in perl which first extracts the
> images/text via the lo_export into a temp directory on my server and then
> it'll display the contents of the file on an HTML page passing HTML headers
> inbetween.
>
> it seems to work fine but it is an extra overhead when it creates  a tmp
> file. How can this be cached? Or can it be directed directly to the web page
> instead of having to go through another step of createing a temp file.

Well, what I would have done is:

(a) Create a small CGI which, given sufficient parameters to locate the
    specific BLOB (OID, I suppose, but cases vary), reads it using
    lo_read() and dumps what it reads to its standard output.

(b) Note that this CGI should return the appropriate MIME type in its
    Content-type line. For example, if the image is a JPEG image, its
    standard output should start with "Content-type: image/jpeg".

(c) You could actually make it general-purpose by giving it the content
    type as a parameter. This way it blindly gives the given content
    type and dumps the given large object, so it can be used for both
    image applications and text applications implemented with large
    objects.

In short, you should have a cgi whose URL may look something like:

    http://my.domain.com/cgi-bin/lo-dumper.cgi?oid=NNNNN&mime=image/jpeg

When you have one, you can use it as your image source. Just write your
image output with the above URL as its source:

   <IMG SRC="/cgi-bin/lo-dumper.cgi?oid=123456@mime=image/jpeg"
    WIDTH=100 HEIGHT=40 ALT="Image of a bear">

How did all the parameters get there? Well, I assume that anybody holding
an image database will have an image table, which has fields for the image
name or details (which can be used in the ALT), its width and height, and
if there are several image types, also its type (jpeg, gif, png).

So, at the bottom line, you have two CGIs. One CGI is the one you already
had - the one that displays the HTML that surrounds the image, as well as
selecting which image to display. In this case, this CGI will have to have
a select statement of the general form:

SELECT image_lo, image_type, width, height, description
FROM image_table
WHERE ....;

And it should then print out the call to the other CGI in the form of an
IMG tag as before, based on the details retrieved in the above select
statement.

You make your choice of languague for writing those two CGIs (or servlets).

Hope this gives you a more complete picture of how things should be done
for direct display of images.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-general by date:

Previous
From: Ralf Weidemann
Date:
Subject: database destroy failed !
Next
From: "Robert Nosko"
Date:
Subject: Agents